home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / ExtendedEWA.cs677 < prev    next >
Text File  |  2008-03-01  |  5KB  |  173 lines

  1. using System;
  2. using System.Collections;
  3. using System.Data.Common;
  4. using System.Data.SQLite;
  5. using System.IO;
  6. using System.Web;
  7.  
  8. namespace gbweb
  9. {
  10.     public class ExtendedEWA
  11.     {
  12.         public enum Role
  13.         {
  14.             Actor = 1,
  15.             Director = 2,
  16.             Producer = 3,
  17.             Writer = 4,
  18.             ExecProducer = 5,
  19.             GuestStar = 6,
  20.             Host = 7,
  21.             Narrator = 9,
  22.             Judge = 10,
  23.             Contestant = 11,
  24.             Guest = 12
  25.         }
  26.  
  27.         private static string databaseFileName;
  28.  
  29.         private static DbConnection ExtendedEWAConnection
  30.         {
  31.             get
  32.             {
  33.                 return HttpContext.Current.Items["ExtendedEWAConnection"] as DbConnection;
  34.             }
  35.             set
  36.             {
  37.                 HttpContext.Current.Items["ExtendedEWAConnection"] = value;
  38.             }
  39.         }
  40.  
  41.         // TODO: All these statics are creating a race condition on page processing
  42.         public static bool Initialize()
  43.         {
  44.             if (databaseFileName == null)
  45.             {
  46.                 databaseFileName = Path.Combine(Global.Settings.GetInstallDir(), "ExtendedEWA.db3");
  47.             }
  48.             return File.Exists(databaseFileName);
  49.         }
  50.  
  51.         public static void OpenExtendedEWADB()
  52.         {
  53.             if (File.Exists(Path.Combine(Global.Settings.GetInstallDir(), "ExtendedEWA.db3")))
  54.             {
  55.                 DbProviderFactory ExtendedEWAFactory = new SQLiteFactory();
  56.                ExtendedEWAConnection = ExtendedEWAFactory.CreateConnection();
  57.                ExtendedEWAConnection.ConnectionString = "Data Source=" + databaseFileName + ";Version=3;New=True";
  58.             }
  59.             else
  60.             {
  61.                DbProviderFactory ExtendedEWAFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
  62.                ExtendedEWAConnection = ExtendedEWAFactory.CreateConnection();
  63.                ExtendedEWAConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databaseFileName;
  64.             }
  65.             ExtendedEWAConnection.Open();
  66.         }
  67.  
  68.         public static void CloseExtendedEWADB()
  69.         {
  70.             ExtendedEWAConnection.Close();
  71.         }
  72.  
  73.         public static bool IsNew(string UniqueProgrammeIdentifier)
  74.         {
  75.             byte isNew = 0;
  76.  
  77.             // create the command object and store the sql query
  78.             DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
  79.             aCommand.CommandText = "select new_show from Schedule where scheduleid='" + UniqueProgrammeIdentifier + "'";
  80.             aCommand.Connection = ExtendedEWAConnection;
  81.             DbDataReader aReader = aCommand.ExecuteReader();
  82.  
  83.             // read from the database
  84.             if (aReader.Read())
  85.             {
  86.                 isNew = aReader.GetByte(0);
  87.             }
  88.  
  89.             // close the reader
  90.             aReader.Close();
  91.  
  92.             return isNew != 0;
  93.         }
  94.  
  95.         public static bool IsHD(string UniqueProgrammeIdentifier)
  96.         {
  97.             byte isHDValue = 0;
  98.  
  99.             // create the command object and store the sql query
  100.             DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
  101.             aCommand.CommandText = "select hd from Schedule where scheduleid='" + UniqueProgrammeIdentifier + "'";
  102.             aCommand.Connection = ExtendedEWAConnection;
  103.             DbDataReader aReader = aCommand.ExecuteReader();
  104.  
  105.             // read from the database
  106.             if (aReader.Read())
  107.             {
  108.                 isHDValue = aReader.GetByte(0);
  109.             }
  110.  
  111.             // close the reader
  112.             aReader.Close();
  113.  
  114.             return isHDValue != 0;
  115.         }
  116.  
  117.         public static string[] GetProgramInfo(string UniqueProgrammeIdentifier)
  118.         {
  119.             string[] programInfo = new string[] {};
  120.  
  121.             // create the command object and store the sql query
  122.             DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
  123.             aCommand.CommandText = "select year_released,air_date,star_rating from ProgramData where program_id='" + UniqueProgrammeIdentifier + "'";
  124.             aCommand.Connection = ExtendedEWAConnection;
  125.             DbDataReader aReader = aCommand.ExecuteReader();
  126.  
  127.             // read from the database
  128.             if (aReader.Read())
  129.             {
  130.                 programInfo = new string[] {
  131.                     Convert.ToString(aReader.GetInt32(0)), 
  132.                     aReader.GetString(1), 
  133.                     aReader.GetString(2)};
  134.             }
  135.  
  136.             // close the reader
  137.             aReader.Close();
  138.  
  139.             return programInfo;
  140.         }
  141.  
  142.         public static ArrayList GetCast(string UniqueProgrammeIdentifier)
  143.         {
  144.             ArrayList list = new ArrayList();
  145.             // create the command object and store the sql query
  146.             DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
  147.             aCommand.CommandText = "select DISTINCT givenname,surname,role FROM Crew where program_id='" + UniqueProgrammeIdentifier + "' ORDER BY role";
  148.             aCommand.Connection = ExtendedEWAConnection;
  149.             DbDataReader aReader = aCommand.ExecuteReader();
  150.  
  151.             // iterate through the database
  152.             while(aReader.Read())
  153.             {
  154.                 Crew crew = new Crew();
  155.                 crew.GivenName = aReader.GetString(0);
  156.                 crew.SurName = aReader.GetString(1);
  157.                 crew.Role = (Role)aReader.GetByte(2);
  158.                 list.Add(crew);
  159.             }
  160.             // close the reader
  161.             aReader.Close();
  162.             return list;
  163.         }
  164.  
  165.         public struct Crew
  166.         {
  167.             public string GivenName;
  168.             public string SurName;
  169.             public Role Role;
  170.         }
  171.     }
  172. }
  173.